<template>
    <view>
        <view class="container">
            <view class="simple" v-if="simpleModel">
                <!-- banner -->
                <view class="banner">
                    <swiper autoplay indicator-dots>
                        <block v-if="bannerImg.length">
                            <block v-for="(item, index) in bannerImg" :key="index">
                                <swiper-item>
                                    <image :src="item" mode="scaleToFill"></image>
                                </swiper-item>
                            </block>
                        </block>
                    </swiper>
                </view>
                <!-- 门店信息 -->
                <view class="intro">
                    <view class="line1">
                        <image class="image" src="/static/logo.png"></image>
                        <text class="name">{{ doorinfodata.storeName }}</text>
                        <button class="qhBtn" @tap="goIndexPage">切换门店 ></button>
                    </view>
                    <view class="line2">
                        <view class="address" @tap="goDoorDetail">
                            {{ doorinfodata.address }}
                        </view>
                        <view class="btns">
                            <text class="iconfont icon-weizhi btn" @tap="goTencentMap" :data-info="doorinfodata"></text>
                            <text class="iconfont icon-phone btn" @tap="call"></text>
                        </view>
                    </view>
                </view>
                <!-- 快捷入口 -->
                <view class="toolbar" id="toolbar">
                    <view class="item" @tap="showWifi">
                        <view class="bg-primary iconfont icon-wifi"></view>
                        <view class="name">WiFi连接</view>
                    </view>
                    <view class="item" @tap="gototuangou">
                        <view class="bg-primary iconfont icon-quan"></view>
                        <view class="name">团购验券</view>
                    </view>
                    <view class="item" @tap="goRecharge">
                        <view class="bg-primary iconfont icon-chongzhi"></view>
                        <view class="name">优惠充值</view>
                    </view>
                    <view class="item" @tap="call">
                        <view class="bg-primary iconfont icon-kefu"></view>
                        <view class="name">联系客服</view>
                    </view>
                </view>
                <view class="top-tabs-container">
                    <view class="top-tabs">
                        <view data-index="0" :class="'tab ' + (tabIndex === 0 && 'active')" @tap="tabChange">棋牌</view>
                        <view data-index="1" :class="'tab ' + (tabIndex === 1 && 'active')" @tap="tabChange">台球</view>
                        <!-- <view data-index="2" class="tab {{tabIndex === 2 && 'active'}}" bind:tap="tabChange">自习室</view> -->
                    </view>
                </view>
                <!-- 房间列表 -->
                <view class="lists" id="roomList" v-for="(item, index) in doorlistArr" :key="index">
                    <view class="item">
                        <view class="top">
                            <view class="left">
                                <block v-if="item.imageUrls.length > 0">
                                    <image class="img" :src="magic.split(item.imageUrls)[0]" @tap.stop.prevent="imgYu" :data-index="index"></image>
                                </block>
                                <block v-else>
                                    <image class="img" src="/static/logo.png"></image>
                                </block>
                                <block v-if="item.status == 0">
                                    <view class="flag disabled">禁用</view>
                                </block>
                                <block v-else-if="item.status == 1">
                                    <view class="flag undo">空闲中</view>
                                </block>
                                <block v-else-if="item.status == 2">
                                    <view class="flag daiqingjie">待清洁</view>
                                </block>
                                <block v-else-if="item.status == 3">
                                    <view class="flag doing">使用中</view>
                                </block>
                                <block v-else>
                                    <view class="flag bukeyong">已预约</view>
                                </block>
                            </view>
                            <view class="right" @tap="goOrder" :data-status="item.status" :data-index="index" :data-info="item.roomId">
                                <view class="info">
                                    <view class="name">
                                        {{ item.roomName }}
                                        (
                                        <block v-if="item.type == 0">
                                            <text class="type">特价包</text>
                                        </block>
                                        <block v-else-if="item.type == 1">
                                            <text class="type">小包</text>
                                        </block>
                                        <block v-else-if="item.type == 2">
                                            <text class="type">中包</text>
                                        </block>
                                        <block v-else-if="item.type == 3">
                                            <text class="type">大包</text>
                                        </block>
                                        <block v-else-if="item.type == 4">
                                            <text class="type">豪包</text>
                                        </block>
                                        <block v-else>
                                            <text class="type">商务包</text>
                                        </block>
                                        )
                                    </view>
                                    <view class="tags">
                                        <block v-for="(labelitem, index1) in magic.split(item.label)" :key="index1">
                                            <view class="tag">{{ labelitem }}</view>
                                        </block>
                                    </view>
                                </view>
                                <view class="line2">
                                    <view class="priceLabel">
                                        <view class="price">
                                            每小时
                                            <label class="color-attention">￥{{ item.price }}元</label>
                                        </view>
                                    </view>
                                    <view class="bottom">
                                        <block v-if="item.status == 0">
                                            <!-- 禁用状态 -->
                                            <view class="btn disabled">禁用</view>
                                        </block>
                                        <block v-else-if="">
                                            <view class="btn bg-primary">预约</view>
                                        </block>
                                    </view>
                                </view>
                            </view>
                        </view>
                        <view class="foot">
                            <view class="foot-top">
                                <view class="labels">
                                    <view class="label disabled">不可用</view>
                                    <view class="label">可预约</view>
                                </view>
                                <block v-if="item.status == 3">
                                    <view class="tip color-attention" v-if="item.endTime">使用中 | {{ item.endTime }}结束</view>
                                </block>
                                <!-- <block wx:elif="{{item.status == 4 ||item.status == 2}}">
            <view class="tip color-attention" wx:if="{{item.endTime}}">
              已预订 | {{item.startTime}}开始
            </view>
          </block> -->
                            </view>
                            <view class="times">
                                <block v-for="(houritem2, index1) in timeHourAllArr[index]" :key="index1">
                                    <view :class="'time ' + (houritem2.disable ? 'disabled' : '')">{{ houritem2.hour }}</view>
                                </block>
                            </view>
                        </view>
                    </view>
                </view>
                <!-- <view class="notes">
    <view class="title border-primary">温馨提示</view>
    <view class="line">1.下单5分钟内可以取消订单或更换房间，超时将无法取消！</view>
    <view class="line">2.订单可以提前开始消费，提前开始提前结束。</view>
    <view class="line">3.消费时间不足时，我们进行提醒。若房间后续时间已被他人预定，将无法续费！请您留意消费时长！</view>
    <view class="line">4.预约时间结束后，房间将断电，灯光会自动熄灭。为了不影响下一位朋友使用，请您及时收拾物品离席。</view>
    <view class="line">5.严禁黄、赌、毒打架斗殴等一切违法活动！</view>
    <view class="line">6.破坏或带走本场所提供的设备设施请照价赔偿！</view>
    <view class="line">7.请自行保管好私人物品，如有遗失概不负责！</view>
    <view class="line">8.特殊情况，或需要帮助，请联系客服处理！</view>
  </view> -->
            </view>

            <view class="custom" v-else>
                <!-- banner -->
                <block v-if="storeEnvImg.length">
                    <view class="banner">
                        <swiper autoplay indicator-dots>
                            <block v-for="(item, index) in bannerImg" :key="index">
                                <swiper-item>
                                    <image :src="item" mode="scaleToFill"></image>
                                </swiper-item>
                            </block>
                        </swiper>
                    </view>
                </block>
                <!-- 地点 -->
                <view class="intro">
                    <view class="address" @tap="goDoorDetail">
                        <view class="iconfont icon-dingwei"></view>
                        <text style="font-size: 20rpx">{{ doorinfodata.address }}</text>
                    </view>
                    <view class="btns">
                        <view class="iconfont icon-weizhi btn" @tap="goTencentMap" :data-info="doorinfodata"></view>
                    </view>
                </view>
                <!-- 快捷入口 -->
                <view class="toolbar" id="toolbar">
                    <view class="line1">
                        <!-- 预约 -->
                        <view hover-class="button-click" class="yuyue" @tap="goYuyue" :style="'background-image: url(' + doorinfodata.btnImg + ')'"></view>
                        <!-- <view hover-class="button-click" class="yuyue" bind:tap="gotest" style="background-image: url({{doorinfodata.btnImg}})"></view> -->
                        <view class="right-box">
                            <!-- 切换门店 -->
                            <view class="storename sub-item" @tap="goIndexPage" :style="'background-image: url(' + doorinfodata.qhImg + ')'"></view>
                            <!-- 团购验券 -->
                            <view hover-class="button-click" class="group-buying sub-item" @tap="gototuangou" :style="'background-image: url(' + doorinfodata.tgImg + ')'"></view>
                        </view>
                    </view>
                    <view class="line2">
                        <!-- 余额充值 -->
                        <view hover-class="button-click" class="slim sub-item margin-t-26" @tap="goRecharge" :style="'background-image: url(' + doorinfodata.czImg + ')'"></view>
                        <view hover-class="button-click" class="sub-item margin-t-26 slim" @tap="openDoor" :style="'background-image: url(' + doorinfodata.openImg + ')'"></view>
                        <view hover-class="button-click" class="sub-item margin-t-26 slim" @tap="showWifi" :style="'background-image: url(' + doorinfodata.wifiImg + ')'"></view>
                        <view hover-class="button-click" class="sub-item margin-t-26 slim" @tap="call" :style="'background-image: url(' + doorinfodata.kfImg + ')'"></view>
                    </view>
                </view>
                <view class="section">
                    <block v-if="storeEnvImg.length">
                        <view class="title">门店介绍</view>
                        <view class="content">
                            <block v-for="(item, index) in storeEnvImg" :key="index">
                                <image :src="item" mode="widthFix"></image>
                            </block>
                        </view>
                    </block>
                </view>
            </view>
        </view>

    

        <van-dialog use-slot title="WiFi信息" class="wifiDialog" :show="wifiShow">
            <view class="dialog">
                <view class="item">
                    <label>WiFi名称:</label>
                    <text>{{ doorinfodata.wifiInfo }}</text>
                </view>
                <view class="item">
                    <label>Wifi密码:</label>
                    <text>{{ doorinfodata.wifiPwd }}</text>
                </view>
                <view class="btn">
                    <button class="copy" @tap="copyWifi" :data-ssid="doorinfodata.wifiInfo" :data-pwd="doorinfodata.wifiPwd">复制密码</button>
                    <button class="connect" @tap="connectWifi" :data-ssid="doorinfodata.wifiInfo" :data-pwd="doorinfodata.wifiPwd">一键连接</button>
                </view>
                <view class="info">部分机型不支持一键连接,请复制密码自行连接</view>
            </view>
        </van-dialog>
    </view>
</template>
<script module="magic" lang="wxs" src="@/utils/magic.wxs"></script>
<script>
// pages/doorList/doorList.js
const app = getApp();
var http = require('../../utils/http');
var util1 = require('../../utils/util.js');
export default {
    data() {
        return {
            statusBarHeight: '',
            titleBarHeight: '',
            storeId: '',
            storeEnvImg: [],

            //图片数组
            bannerImg: [],

            //banner
            doorinfodata: {
                storeName: '',
                address: '',
                btnImg: '',
                qhImg: '',
                tgImg: '',
                czImg: '',
                openImg: '',
                wifiImg: '',
                kfImg: '',
                notice: '',
                wifiInfo: '',
                wifiPwd: ''
            },

            //门店信息
            timeselectindex: 0,

            //日期选择索引值
            timebg_primary: 'bg-primary',

            timebg_primary_no: '',
            timeDayArr: [],

            //时间展示日期：年月日
            timeWeekArr: [],

            //时间展示：星期
            doorlistArr: [],

            //房间数组
            timeHourArr: [],

            //小时数组
            timeHourAllArr: [],

            //所有门店小时数组
            isLogin: app.globalData.isLogin,

            popshow: false,
            wifiShow: false,
            simpleModel: '',

            //简洁模式
            maoHeight: 0,

            //锚链接跳转高度
            tabIndex: 0,

            labelitem: '',

            houritem2: {
                disable: false,
                hour: ''
            }
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad(options) {
        this.setData({
            isLogin: app.globalData.isLogin
        });
        console.log('onLoad index');
        var that = this;
        that.getTap();
        console.log(options);
        var storeId = '';
        if (options.storeId) {
            storeId = options.storeId;
        }
        var query = uni.getEnterOptionsSync().query;
        console.log(query);
        if (query && query.storeId) {
            storeId = query.storeId;
        }
        if (storeId) {
            that.setData({
                storeId: storeId
            });
            uni.setStorageSync('global_store_id', storeId);
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {},
    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        console.log('onShow index');
        var that = this;
        that.setData({
            isLogin: app.globalData.isLogin
        });
        var popshow = false; //默认不显示广告
        //尝试从缓存获取
        var storeId_1 = uni.getStorageSync('global_store_id');
        var storeId_2 = that.storeId; //页面的
        console.log('storeId_1=' + storeId_1);
        console.log('storeId_2=' + storeId_2);
        //如果两个都是空的，让用户去选择门店
        if (!storeId_1 && !storeId_2) {
            console.log('未获取到门店id');
            uni.navigateTo({
                url: '../doorList/doorList'
            });
        } else {
            //至少有一个不为空
            //只处理不相等的情况，控制显示公告弹窗，相等的情况说明停留在当前门店
            if (storeId_1 != storeId_2) {
                popshow = true;
                if (!storeId_1) {
                    //如果缓存为空，可能是用户第一次扫码那就以扫码的为准
                    that.setData({
                        storeId: storeId_2
                    });
                } else {
                    //缓存有  页面也有 优先缓存
                    that.setData({
                        storeId: storeId_1
                    });
                }
            }
        }
        console.log('最终的门店id:' + that.storeId);
        if (that.storeId) {
            that.loadingtime();
            that.getDoorInfodata();
            that.setData({
                popshow: popshow
            });
        }
        this.getDoorListdata();
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {},
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {},
    methods: {
        popClose: function () {
            this.setData({
                popshow: false
            });
        },

        loadingtime: function () {
            var that = this;
            var date = new Date(); //获取当前时间
            var year = date.getFullYear(); //获取当前年份
            var month = date.getMonth() + 1; //获取当前月份
            var day = date.getDate(); //获取当前日期
            var atimestring = year + '-' + month + '-' + day;
            var atimestring1 = [year, month, day].map(util1.formatNumber).join('-');
            //console.log('atimestring1===11111');
            //console.log(atimestring1);

            var atimelist = that.getDates(5, atimestring1);
            var alist1 = [];
            var alist2 = [];
            for (var i = 0; i < atimelist.length; i++) {
                alist1.push(atimelist[i].month + '.' + atimelist[i].day);
                alist2.push(atimelist[i].week);
            }
            that.setData({
                timeDayArr: alist1,
                timeWeekArr: alist2
            });
        },

        //获取当前时间多少天后的日期和对应星期
        getDates: function (days, todate) {
            //todate默认参数是当前日期，可以传入对应时间
            var dateArry = [];
            for (var i = 0; i < days; i++) {
                var dateObj = this.dateLater(todate, i);
                dateArry.push(dateObj);
            }
            return dateArry;
        },

        /**
         * 传入时间后几天
         * param：传入时间：dates:"2019-04-12",later:往后多少天
         */
        dateLater: function (dates, later) {
            let dateObj = {};
            let show_day = new Array('周日', '周一', '周二', '周三', '周四', '周五', '周六');
            let date = new Date(dates);
            date.setDate(date.getDate() + later);
            let day = date.getDay();
            dateObj.year = date.getFullYear();
            dateObj.month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1;
            dateObj.day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
            dateObj.week = show_day[day];
            return dateObj;
        },

        getTap() {
            const SelectorQuery = uni.createSelectorQuery();
            SelectorQuery.select('#toolbar').boundingClientRect();
            SelectorQuery.exec((res) => {
                this.setData({
                    maoHeight: res[0].bottom + 200
                });
            });
        },

        showWifi() {
            this.setData({
                wifiShow: true
            });
        },

        goTencentMap(e) {
            var store = e.currentTarget.dataset.info;
            this.goMap(store);
        },

        //续费
        onclickxufei: function () {
            uni.showToast({
                title: '未找到订单',
                icon: 'none'
            });
        },

        // 打开地图
        goMap(store) {
            uni.openLocation({
                latitude: store.lat,
                longitude: store.lon,
                name: store.storeName,
                address: store.address,
                scale: 28
            });
        },

        goYuyue() {
            uni.navigateTo({
                url: `/pages/booking/booking?storeId=${this.storeId}`
            });
        },

        goIndexPage() {
            console.log(this.storeId);
            uni.navigateTo({
                url: '/pages/doorList/doorList?storeId=' + this.storeId
            });
        },

        goDoorDetail() {
            var that = this;
            uni.navigateTo({
                url: '../doorDetail/doorDetail?storeId=' + that.storeId
            });
        },

        tempArr: function (key) {
            Object.keys(aobject.disabledTimeSlot)
                .sort()
                .forEach(function (key) {
                    requestArr.push(key + '=' + aobject.disabledTimeSlot[key]);
                });
        },

        goOrder(e) {
            var that = this;
            let status = e.currentTarget.dataset.status;
            if (status == 0) {
                return;
            }
            let aroomid = e.currentTarget.dataset.info;
            var atime = '';
            if (that.timeselectindex >= 0) {
                atime = that.timeDayArr[that.timeselectindex];
            }
            var storeId = that.storeId;
            if (status == 2) {
                if (that.doorinfodata.clearOpen) {
                    uni.showModal({
                        title: '提示',
                        content: '您选择的此场地暂未清洁，介意请勿预订！',
                        confirmText: '继续预定',
                        complete: (res) => {
                            if (res.confirm) {
                                uni.navigateTo({
                                    url: '../orderSubmit/orderSubmit?roomId=' + aroomid + '&daytime=' + atime + '&storeId=' + storeId + '&timeselectindex=' + that.timeselectindex
                                });
                            } else if (res.cancel) {
                                //console.log('用户点击取消')
                            }
                        }
                    });
                } else {
                    uni.showModal({
                        title: '提示',
                        content: '房间暂未清洁，禁止预订！',
                        showCancel: false
                    });
                }
            } else {
                uni.navigateTo({
                    url: '../orderSubmit/orderSubmit?roomId=' + aroomid + '&daytime=' + atime + '&storeId=' + storeId + '&timeselectindex=' + that.timeselectindex
                });
            }
        },

        phone: function (e) {
            var that = this;
            //console.log('手机号码授权+++++++');
            if (e.detail.errMsg == 'getPhoneNumber:fail user deny') {
                uni.showToast({
                    title: '已取消授权'
                });
            }
            if (e.detail.errMsg == 'getPhoneNumber:ok') {
                //console.log('手机号码授权+++++++');
                uni.login({
                    success: function (res) {
                        if (res.code != null) {
                            http.request(
                                '/member/auth/weixin-mini-app-login',
                                '1',
                                'post',
                                {
                                    phoneCode: e.detail.code,
                                    loginCode: res.code
                                },
                                '',
                                '获取中...',
                                function success(info) {
                                    console.info('返回111===');
                                    console.info(info);
                                    if (info.code == 0) {
                                        if (info.data) {
                                            app.globalData.userDatatoken = info.data;
                                            app.globalData.isLogin = true;
                                            that.setData({
                                                isLogin: true
                                            });
                                            //缓存服务器返回的用户信息
                                            uni.setStorageSync('userDatatoken', info.data);
                                            this.goOrder(e);
                                        }
                                    }
                                },
                                function fail(info) {}
                            );
                        } else {
                            //console.log('登录失败！' + res.errMsg)
                        }
                    }
                });
            }
        },

        //获取房间列表数据
        getDoorListdata: function (e) {
            var that = this;
            //if (app.globalData.isLogin)
            {
                http.request(
                    '/member/index/getRoomInfoList/' + that.storeId + '?roomClass=' + that.tabIndex,
                    '1',
                    'post',
                    {
                        storeId: that.storeId
                    },
                    app.globalData.userDatatoken.accessToken,
                    '获取中...',
                    function success(info) {
                        console.info('返回111===');
                        console.info(info);
                        if (info.code == 0) {
                            that.setData({
                                doorlistArr: info.data
                            });
                            that.setroomlistHour(0);
                        } else {
                            uni.showModal({
                                content: '请求服务异常，请稍后重试',
                                showCancel: false
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        //设置列表禁用时间轴
        setroomlistHour: function (aindex) {
            //aindex代表选的第几天  从0开始
            var that = this;
            console.log(aindex);
            var atemplist = [];
            //根据门店循环
            for (var i = 0; i < that.doorlistArr.length; i++) {
                var atemp = that.doorlistArr[i].timeSlot.slice(aindex * 24, aindex * 24 + 24);
                atemplist.push(atemp);
                // console.log(atemp);
            }

            console.log(atemplist);
            that.setData({
                timeHourAllArr: atemplist
            });
        },

        //获取门店相信信息
        getDoorInfodata: function (e) {
            var that = this;
            //if (app.globalData.isLogin)
            {
                http.request(
                    '/member/index/getStoreInfo/' + that.storeId,
                    '1',
                    'get',
                    {},
                    app.globalData.userDatatoken.accessToken,
                    '获取中...',
                    function success(info) {
                        console.info('门店信息===');
                        // console.info(info);
                        if (info.code == 0) {
                            if (null != info.data) {
                                that.setData({
                                    doorinfodata: info.data,
                                    simpleModel: info.data.simpleModel
                                });
                                if (null != info.data.storeEnvImg && info.data.storeEnvImg.length > 0) {
                                    var arr = info.data.storeEnvImg.split(',');
                                    that.setData({
                                        storeEnvImg: arr
                                    });
                                }
                                if (null != info.data.bannerImg && info.data.bannerImg.length > 0) {
                                    var arr = info.data.bannerImg.split(',');
                                    that.setData({
                                        bannerImg: arr
                                    });
                                }
                            } else {
                                uni.navigateTo({
                                    url: '../doorList/doorList'
                                });
                            }
                        } else {
                            uni.showModal({
                                content: '请求服务异常，请稍后重试',
                                showCancel: false
                            });
                            uni.navigateTo({
                                url: '../doorList/doorList'
                            });
                        }
                    },
                    function fail(info) {}
                );
            }
        },

        call: function () {
            let that = this;
            var phoneLength = that.doorinfodata.kefuPhone.length;
            if (phoneLength > 0) {
                if (phoneLength == 11) {
                    uni.makePhoneCall({
                        phoneNumber: that.doorinfodata.kefuPhone,
                        success: function () {
                            //console.log("拨打电话成功！")
                        },
                        fail: function () {
                            //console.log("拨打电话失败！")
                        }
                    });
                } else {
                    uni.showModal({
                        title: '提示',
                        content: '客服上班时间10：00~23：00\r\n如您遇到问题，建议先查看“使用帮助”！\r\n本店客服微信号：' + that.doorinfodata.kefuPhone,
                        confirmText: '复制',
                        complete: (res) => {
                            if (res.confirm) {
                                uni.setClipboardData({
                                    data: that.doorinfodata.kefuPhone,
                                    success: function (res) {
                                        uni.showToast({
                                            title: '微信号已复制到剪贴板！'
                                        });
                                    }
                                });
                            } else if (res.cancel) {
                                //console.log('用户点击取消')
                            }
                        }
                    });
                }
            }
        },

        //选中时间
        selectTime: function (e) {
            let that = this;
            var index = e.currentTarget.dataset.index; //获取当前点击的下标
            that.setData({
                timeselectindex: index
            });
            that.setroomlistHour(index);
        },

        //充值
        goRecharge() {
            var that = this;
            var storeId = that.storeId;
            if (that.isLogin) {
                uni.navigateTo({
                    url: '../recharge/recharge?storeId=' + storeId
                });
            } else {
                that.gotologin();
            }
        },

        //团购
        gototuangou() {
            var that = this;
            uni.navigateTo({
                url: '../tuangou/tuangou'
            });
        },

        //在线组局
        gotodoor() {
            var that = this;
            var data = {
                cityName: that.doorinfodata.cityName,
                storeId: that.doorinfodata.storeId
            };
            uni.setStorageSync('door', data);
            uni.reLaunch({
                url: '../door/door'
            });
        },

        openDoor(e) {
            var that = this;
            // let aindex = e.currentTarget.dataset.index;
            if (that.isLogin) {
                uni.navigateTo({
                    url: '../orderDetail/orderDetail?toPage=true'
                });
            } else {
                that.gotologin();
            }
        },

        //到登录界面
        gotologin() {
            uni.navigateTo({
                url: '../login/login'
            });
        },

        //图片点击事件
        imgYu: function (event) {
            var that = this;
            let aindex = event.currentTarget.dataset.index;
            var alistimage = that.doorlistArr[aindex];
            var aimagearr = alistimage.imageUrls;

            //console.log("点击图片********")

            if (aimagearr.length > 0) {
                var anewimagearr = aimagearr.split(',');
                var src = anewimagearr[0] + '?Content-Type=image/jpg'; //获取data-src
                var imgList = anewimagearr; //获取data-list
                //图片预览
                uni.previewImage({
                    current: src,
                    // 当前显示图片的http链接
                    urls: imgList // 需要预览的图片http链接列表
                });
            } else {
                uni.showToast({
                    title: '该房间暂无图片介绍',
                    icon: 'none'
                });
            }
        },

        gotest: function () {
            uni.navigateTo({
                url: '../roomRenew/roomRenew?storeId=12&roomId=20'
            });
        },

        copyWifi: function (e) {
            let ssid = e.currentTarget.dataset.ssid;
            let pwd = e.currentTarget.dataset.pwd;
            uni.setClipboardData({
                data: pwd,
                success: function (res) {
                    uni.showToast({
                        title: '已复制到剪贴板！'
                    });
                }
            });
            this.setData({
                wifiShow: false
            });
        },

        connectWifi: function (e) {
            var that = this;
            let ssid = e.currentTarget.dataset.ssid;
            let pwd = e.currentTarget.dataset.pwd;
            uni.startWifi({
                success(res) {
                    // console.log(res.errMsg)
                    uni.connectWifi({
                        SSID: ssid,
                        password: pwd,
                        success(res) {
                            this.setData({
                                wifiShow: false
                            });
                            uni.showToast({
                                title: '自动连接WiFi成功'
                            });
                        },
                        fail(res) {
                            uni.showToast({
                                title: res
                            });
                        }
                    });
                },
                fail(res) {
                    uni.showToast({
                        title: res
                    });
                }
            });
        },

        tabChange(e) {
            console.log(e);
            const { target } = e;
            this.setData(
                {
                    tabIndex: Number(target.dataset.index)
                },
                () => {
                    this.getDoorListdata();
                }
            );
        }
    }
};
</script>
<style>
@import './index.css';
</style>
